<?php
class ExchangeForm extends Form{
	function ExchangeForm(){
		Form::Form('ExchangeForm');
		AZLib::get_config();
	}
	
	function on_submit()
	{
		$exchange 	= Url::get('exchange');
		
		if($exchange == '')
		{
			$this->setFormError('exchange','Bạn chưa nhập vào tỷ giá!');
			return;
		}
		
		$exchange 	= Url::cdouble(Url::get('exchange'));
		
		if($exchange <= 0)
		{
			$this->setFormError('exchange','Tỷ giá phải là 1 số nguyên > 0!');
			return;
		}
		
		if(isset(CGlobal::$configs['exchange']))
			DB::update('configs',array("conf_val"=>$exchange),"conf_key='exchange'", __FILE__." Dòng:".__LINE__);
		else
			DB::insert('configs',array("conf_key"=>'exchange',"conf_val"=>$exchange), __FILE__." Dòng:".__LINE__);
		
		AZLib::get_config(0,1);
		
		Url::redirect_current();
	}
	
	function draw()
	{
		global $display;
			
		$exchange = (int)@CGlobal::$configs['exchange']['conf_val'];
		
		if($exchange > 0)
		{
			$display->add("exchange",number_format($exchange,null,null,'.'));
		}
		else
		{
			$display->add("exchange",'20.006');
		}
		
		$display->add("msg",$this->showFormErrorMessages(1));
		
		$this->beginForm();
		$display->output("Exchange");
		$this->endForm();
	}
}
?>